package core.proto.timeline;

import java.awt.Color;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JTextArea;
import javax.swing.text.BadLocationException;

import core.proto.annotation.Annotation;
import core.proto.annotation.AnnotationEventSource;
import core.proto.annotation.AnnotationFocusListener;
import core.proto.annotation.AnnotationRemovalListener;

import de.jaret.util.date.IntervalImpl;
import de.jaret.util.date.JaretDate;
import de.jaret.util.ui.timebars.model.DefaultTimeBarRowModel;
import de.jaret.util.ui.timebars.model.TimeBarRow;

/**
 * Our own interval class used to put into the timeline. 
 * 
 * A design decision was made to store the annotation text in this class (model) 
 * instead of at the view (the JTextArea) in the {@link core.proto.timeline.SavantIntervalRenderer}.
 * @author Wei
 *
 */
public class AnnotationInterval extends IntervalImpl implements AnnotationRemovalListener {

	private boolean editing = false;
	private Annotation annotation;
	private AnnotationRemovalListener listener = null;
	public final DefaultTimeBarRowModel row; 
	
	public AnnotationInterval(Annotation annotation, JaretDate from, JaretDate to, DefaultTimeBarRowModel row){
		super(from, to);
		this.annotation = annotation;
		this.annotation.getView().addAnnotationRemovalListener(this);
		this.row = row;
	}

	public void setIsEditing(boolean isEditing){
		editing = isEditing;
	}
	
	public boolean isEditing(){
		return editing;
	}

	public Annotation getAnnotation () {
		return this.annotation;
	}
	
	public String getAnnotationTxt () {
		return annotation.getModel().getUserText();
	}

	@Override
	public void annotationRemoved(Object source) {
		this.row.remInterval(this);
	}
}
